package Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;



import com.sun.crypto.provider.RSACipher;

import pojo.User;
import util.DBUtil;

public class UserDaoImpl implements UserDao {

	public User findUser(User u) {
		String sql="select * from users where uname = ? and pwd = ?";
		PreparedStatement pst =null;
		ResultSet rs = null;
		Connection conn = null;
		User user = new User();
    	int m=0;
		try {
			conn=DBUtil.createConnection();
			pst=conn.prepareStatement(sql);
			pst.setString(1, u.getUname());
			pst.setString(2, u.getUpwd());
			rs=pst.executeQuery();
			while(rs.next()){
				user.setUid(rs.getString("uuid"));
				user.setUname(rs.getString("uname"));
				user.setUpwd(rs.getString("pwd"));
			}
			m=pst.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		finally{
			DBUtil.close(conn, pst, rs);
		}
		System.out.println("m="+m);
		if(m==0)return null;
		return user;
	}

}
